package Ppackage;

public class Rectangle
{
    // 表示矩形，通过两个对角点定义
    private Point point1;  // 左下角点
    private Point point2;  // 右上角点

    public Rectangle(Point point1, Point point2)
    {
        this.point1 = point1;
        this.point2 = point2;
    }

    public double getWidth()
    {
        // 计算矩形的宽度
        return Math.abs(point2.getX() - point1.getX());
    }

    public double getHeight()
    {
        // 计算矩形的高度
        return Math.abs(point2.getY() - point1.getY());
    }

    public double getPerimeter()
    {
        // 计算矩形的周长
        return 2 * (getWidth() + getHeight());
    }

    public double getArea()
    {
        // 计算矩形的面积
        return getWidth() * getHeight();
    }
}
